﻿#pragma once

#ifndef MYTHREAD_H
    #define MYTHREAD_H

#include "common.h"

// 自定义头文件
#include "CoordWindow.h"
#include "MusicPlayer.h"

// Qt
//#include <QThread>
//#include <QDebug>

// 定义一个全局变量结构体，用于存储和修改位置
static struct VarPos {
    VarPos()
        : x(0), y(0), z(0), flag_x(1), flag_y(1), flag_z(1) {}
    VarPos(int my_x, int my_y, int my_z) :
        x(my_x), y(my_y), z(my_z), flag_x(1), flag_y(1), flag_z(1) {}
    void set_pos(int set_x, int set_y, int set_z) {
        x = set_x;
        y = set_y;
        z = set_z;
    }
    char flag_x, flag_y, flag_z;
    int x, y, z;
};
extern VarPos var_listener_coord;


// 自定义监听器坐标线程类
class ListenerCoordThread : public QThread
{
    Q_OBJECT

public:
    ListenerCoordThread(QObject *parent = nullptr);
    explicit ListenerCoordThread(QObject* parent = nullptr, CoordWindow* window = nullptr, MusicPlayer* player = nullptr);
    ~ListenerCoordThread();

    CoordWindow* get_coord_window() const { return coord_window; };
    MusicPlayer* get_music_player() const { return my_player; };

    unsigned int sleep_time;


protected:
    void run() override;


signals:
    void started();
    void finished();


public slots:
    void startThread(unsigned int time);
    void stopThread();


private:
    bool m_isRunning;
    CoordWindow* coord_window;
    MusicPlayer* my_player;
};
#endif // MYTHREAD_H